<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for javascripts/dashboard/components/SaveModal.jsx</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../../../prettify.css" />
    <link rel="stylesheet" href="../../../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../../../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../../../index.html">All files</a> / <a href="index.html">javascripts/dashboard/components</a> SaveModal.jsx
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>0/54</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>0/12</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>0/9</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>0/51</span>
      </div>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154</td><td class="line-coverage quiet"><span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">c</span>onst $ = <span class="cstat-no" title="statement not covered" >window.$ = require('jquery');
&nbsp;
<span class="cstat-no" title="statement not covered" >import React from 'react';</span>
<span class="cstat-no" title="statement not covered" >import { Button, FormControl, FormGroup, Radio } from 'react-bootstrap';</span>
<span class="cstat-no" title="statement not covered" >import { getAjaxErrorMsg, showModal } from '../../modules/utils';</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >import ModalTrigger from '../../components/ModalTrigger';</span>
&nbsp;
c</span>onst propTypes = <span class="cstat-no" title="statement not covered" >{
  css: React.PropTypes.string,
  dashboard: React.PropTypes.object.isRequired,
  triggerNode: React.PropTypes.node.isRequired,
};
&nbsp;
class SaveModal extends React.PureComponent {
<span class="fstat-no" title="function not covered" >  constructor(</span>props) <span class="cstat-no" title="statement not covered" >{</span>
    super(props);
<span class="cstat-no" title="statement not covered" >    this.state = {</span>
      dashboard: props.dashboard,
      css: props.css,
      saveType: 'overwrite',
      newDashName: '',
    };
<span class="cstat-no" title="statement not covered" >    this.modal = null;</span>
<span class="cstat-no" title="statement not covered" >    this.handleSaveTypeChange = this.handleSaveTypeChange.bind(this);</span>
<span class="cstat-no" title="statement not covered" >    this.handleNameChange = this.handleNameChange.bind(this);</span>
<span class="cstat-no" title="statement not covered" >    this.saveDashboard = this.saveDashboard.bind(this);</span>
  }
  handleSaveTypeChange(event) {
<span class="cstat-no" title="statement not covered" >    this.setState({</span>
      saveType: event.target.value,
    });
  }
  handleNameChange(event) {
<span class="cstat-no" title="statement not covered" >    this.setState({</span>
      newDashName: event.target.value,
      saveType: 'newDashboard',
    });
  }
  saveDashboardRequest(data, url, saveType) {
    c</span>onst dashboard = <span class="cstat-no" title="statement not covered" >this.props.dashboard;
    c</span>onst saveModal = <span class="cstat-no" title="statement not covered" >this.modal;
<span class="cstat-no" title="statement not covered" >    Object.assign(data, { css: this.props.css });</span>
<span class="cstat-no" title="statement not covered" >    $.ajax(<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" ><span class="fstat-no" title="function not covered" ><span class="fstat-no" title="function not covered" >{</span></span></span></span></span>
      type: 'POST',
      url,
      data: {
        data: JSON.stringify(data),
      },
      success(resp) {
<span class="cstat-no" title="statement not covered" >        saveModal.close();</span>
<span class="cstat-no" title="statement not covered" >        dashboard.onSave();</span>
<span class="cstat-no" title="statement not covered" >        if (saveType === 'newDashboard') {</span>
<span class="cstat-no" title="statement not covered" >          window.location = '/superset/dashboard/' + resp.id + '/';</span>
        } else {
<span class="cstat-no" title="statement not covered" >          showModal({</span>
            title: 'Success',
            body: 'This dashboard was saved successfully.',
          });
        }
      },
      error(error) {
<span class="cstat-no" title="statement not covered" >        saveModal.close();</span>
        c</span>onst errorMsg = <span class="cstat-no" title="statement not covered" >getAjaxErrorMsg(error);
<span class="cstat-no" title="statement not covered" >        showModal({</span>
          title: 'Error',
          body: 'Sorry, there was an error saving this dashboard: &lt;/ br&gt;' + errorMsg,
        });
      },
    });
  }
  saveDashboard(saveType, newDashboardTitle) {
    c</span>onst dashboard = <span class="cstat-no" title="statement not covered" >this.props.dashboard;
    c</span>onst expandedSlices = <span class="cstat-no" title="statement not covered" >{};
<span class="cstat-no" title="statement not covered" >    $.each($('.slice_info'), <span class="fstat-no" title="function not covered" >function () </span>{</span>
      c</span>onst widget = <span class="cstat-no" title="statement not covered" >$(this).parents('.widget');
      c</span>onst sliceDescription = <span class="cstat-no" title="statement not covered" >widget.find('.slice_description');
<span class="cstat-no" title="statement not covered" >      if (sliceDescription.is(':visible')) {</span>
<span class="cstat-no" title="statement not covered" >        expandedSlices[$(widget).attr('data-slice-id')] = true;</span>
      }
    });
    c</span>onst positions = <span class="cstat-no" title="statement not covered" >dashboard.reactGridLayout.serialize();
    c</span>onst data = <span class="cstat-no" title="statement not covered" >{
      positions,
      css: this.state.css,
      expanded_slices: expandedSlices,
    };
    l</span>et url = <span class="cstat-no" title="statement not covered" >null;
<span class="cstat-no" title="statement not covered" >    if (saveType === 'overwrite') {</span>
<span class="cstat-no" title="statement not covered" >      url = '/superset/save_dash/' + dashboard.id + '/';</span>
<span class="cstat-no" title="statement not covered" >      this.saveDashboardRequest(data, url, saveType);</span>
    } else <span class="cstat-no" title="statement not covered" >if (saveType === 'newDashboard') {</span>
<span class="cstat-no" title="statement not covered" >      if (!newDashboardTitle) {</span>
<span class="cstat-no" title="statement not covered" >        this.modal.close();</span>
<span class="cstat-no" title="statement not covered" >        showModal({</span>
          title: 'Error',
          body: 'You must pick a name for the new dashboard',
        });
      } else {
<span class="cstat-no" title="statement not covered" >        data.dashboard_title = newDashboardTitle;</span>
<span class="cstat-no" title="statement not covered" >        url = '/superset/copy_dash/' + dashboard.id + '/';</span>
<span class="cstat-no" title="statement not covered" >        this.saveDashboardRequest(data, url, saveType);</span>
      }
    }
  }
  render() <span class="cstat-no" title="statement not covered" >{</span>
<span class="cstat-no" title="statement not covered" >    return (</span>
      &lt;ModalTrigger
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >        ref={<span class="fstat-no" title="function not covered" >(</span>modal) =&gt; { <span class="cstat-no" title="statement not covered" >this.modal = modal; }}</span></span></span>
        triggerNode={this.props.triggerNode}
        isButton
        modalTitle="Save Dashboard"
        modalBody={
          &lt;FormGroup&gt;
            &lt;Radio
              value="overwrite"
              onChange={this.handleSaveTypeChange}
              checked={this.state.saveType === 'overwrite'}
            &gt;
              Overwrite Dashboard [{this.props.dashboard.dashboard_title}]
            &lt;/Radio&gt;
            &lt;Radio
              value="newDashboard"
              onChange={this.handleSaveTypeChange}
              checked={this.state.saveType === 'newDashboard'}
            &gt;
              Save as:
            &lt;/Radio&gt;
            &lt;FormControl
              type="text"
              placeholder="[dashboard name]"
              onFocus={this.handleNameChange}
              onChange={this.handleNameChange}
            /&gt;
          &lt;/FormGroup&gt;
        }
        modalFooter={
          &lt;div&gt;
            &lt;Button
              bsStyle="primary"
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >              onClick={<span class="fstat-no" title="function not covered" >() =&gt; </span>{ <span class="cstat-no" title="statement not covered" >this.saveDashboard(this.state.saveType, this.state.newDashName); }}</span></span></span>
            &gt;
              Save
            &lt;/Button&gt;
          &lt;/div&gt;
        }
      /&gt;
    );
  }
}
<span class="cstat-no" title="statement not covered" >SaveModal.propTypes = propTypes;</span>
&nbsp;
export default SaveModal;
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Apr 11 2017 20:15:55 GMT-0700 (PDT)
</div>
</div>
<script src="../../../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../../../sorter.js"></script>
</body>
</html>
